<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
class Idcord extends Common
{
	/*
	*	实名认证接口
	*	请求方式：  get/post
	*	参数：
			APPID
			APPKEY
			UID
	*	请求方式： get/post
	*	返回格式： json 
	*	
	*/
	public static $appikey = '5ff0db72dd054862bb7b15281d3641f0';
	public function index(Request $request)
	{
		$name = $request->param("name");
		$idcard = $request->param("idcard");
		$uid = $request->param("uid");
		$name = urlencode($name);
		$url="http://apis.haoservice.com/idcard/VerifyIdcard?cardNo=$idcard&realName=$name&key=".self::$appikey;
		$res = file_get_contents($url);
		$arr = json_decode($res,1);
		if($arr['error_code'] == 0){
			$res = Db::table('user')->update(['realName' => $name,'idCard'=>$idcard,'userId'=>$uid]);
			if($res){
				$result['status'] = 200;
				$result['reason'] = '成功';
			}else{
				$result['status'] = 300;
				$result['reason'] = '未知错误';
			}
		}else{
			echo callback(self::$callback,$res);exit;
		}
		echo callback(self::$callback,$result);
	}
}
